Attribute VB_Name = "ModSubClassing"
Option Explicit

Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const SWP_FRAMECHANGED = &H20
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_CREATE = &H1

Public EN As Long
Public rcClient As RECT
Public MG As MARGINS
Public proC As Long


Public Function myPROC(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_CREATE Then
DwmIsCompositionEnabled EN
If EN Then
MG.m_Bottom = -1
MG.m_Left = 5
MG.m_Right = 5
MG.m_Top = 5
DwmExtendFrameIntoClientArea hWnd, MG
GetWindowRect hWnd, rcClient
SetWindowPos hWnd, 0, rcClient.Left, rcClient.Top, rcClient.Right - rcClient.Left, _
rcClient.Bottom - rcClient.Top, SWP_FRAMECHANGED
End If
End If
myPROC = CallWindowProc(proC, hWnd, Msg, wParam, lParam)
End Function

Sub main()
proC = GetWindowLong(Form2.hWnd, GWL_WNDPROC)
SetWindowLong Form2.hWnd, GWL_WNDPROC, AddressOf myPROC
Form2.Show
End Sub
